/*
 * File Name:               ToggleExtenstion.cs
 * 
 * Description:             普通类
 * Author:                  高锐 <gaor2012@gmail.com>
 * Create Date:             2016/12/12
 */

using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;

public static class ScrollbarExtension 
{
    public static void AddListener(this Scrollbar scrollbar, UnityAction<float> onChange)
    {
        if (scrollbar != null)
            scrollbar.onValueChanged.AddListener(onChange);
        else
            Debug.LogWarningFormat("toggle is null");
    }

    public static void removeListener(this Scrollbar scrollbar, UnityAction<float> onChange)
    {
        if (scrollbar != null)
            scrollbar.onValueChanged.RemoveListener(onChange);
        else
            Debug.LogWarningFormat("toggle is null");
    }

    public static void SetListener(this Scrollbar scrollbar, UnityAction<float> onChange)
    {
        if (scrollbar != null)
        {
            scrollbar.onValueChanged.RemoveAllListeners();
            scrollbar.onValueChanged.AddListener(onChange);
        }
        else
            Debug.LogWarningFormat("toggle is null");
    }
}
